using MidnightPeach.Engine.Packages;
using MidnightPeach.Engine.Schema;
using MidnightPeach.Engine.Schema.ServiceSchema;

namespace MidnightPeach.Engine.Generators.ServiceGenerators
{
    class MethodGenerator : ServiceGenerator
    {
        public MethodGenerator(Package package, Method method) : base(package)
        {
            Method = method;
        }

        public Method Method { get; private set; }

        internal override string Generate(Macro macro, string text)
        {
            switch (macro.Value)
            {
                case "Name":
                    return Method.Name;

                case "PascalName":
                    return Method.PascalName;

                case "CamelName":
                    return Method.CamelName;

                case "ReturnType":
                    return Method.ReturnType;

                case "BeginCommentIfVoidReturn":
                    return Method.HasReturnType ? string.Empty : "/* ";

                case "EndCommentIfVoidReturn":
                    return Method.HasReturnType ? string.Empty : "*/ ";

                case "CommaIfHasArguments":
                    return Method.Parameters.Count > 0 ? ", " : string.Empty;

                case "TaskReturnType":
                    return Method.HasReturnType ? string.Format("Task<{0}>", Method.ReturnType) : "Task";

                case "GenericTypes":
                    return Method.GenericTypes;

                case "ListableReturnType":
                    return Method.ListableReturnType;

                case "ListablePostfix":
                    return Method.ListablePostfix;

                default:
                    throw new UnsupportedMacroException(macro, text, this);
            }
        }
    }
}